package com.societyGames.codeAlong.state.codeExercise.model
{
import com.societyGames.codeAlong.state.codeExercise.model.link.ILinkable;
import com.societyGames.codeAlong.state.codeExercise.model.link.Linkable;

public class LibraryData
{
  public var classes:Vector.<ClassData> = new Vector.<ClassData>();
  public var functions:Vector.<FunctionData> = new Vector.<FunctionData>();
  public var globals:Vector.<GlobalData> = new Vector.<GlobalData>();

  public static const separator:String = ":";
  private static const _functionLinkable:ILinkable = new Linkable("function");

  public static function fromXml(xml:XML):LibraryData
  {
    var libraryData:LibraryData = new LibraryData();
    libraryData.addXml(xml);
    return libraryData;
  }

  public function addXml(xml:XML):void
  {
    for each (var classXml:XML in xml["class"])
    {
      classes.push(ClassData.fromXml(classXml));
    }
    for each (var functionXml:XML in xml["function"])
    {
      functions.push(FunctionData.fromXml(_functionLinkable, functionXml));
    }
    for each (var globalXml:XML in xml["global"])
    {
      globals.push(GlobalData.fromXml(globalXml));
    }
  }
}
}